package model

import "kubeInstall/utils"

const NFSManifests = `
kind: Deployment
apiVersion: apps/v1
metadata:
  name: nfs-client-provisioner
  namespace: kube-system
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nfs-client-provisioner
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: nfs-client-provisioner
    spec:
      serviceAccountName: nfs-client-provisioner
      containers:
        - name: nfs-client-provisioner
          image: quay.io/external_storage/nfs-client-provisioner:v3.1.0
          imagePullPolicy: IfNotPresent
          volumeMounts:
            - name: nfs-client-root
              mountPath: /persistentvolumes
          env:
            - name: PROVISIONER_NAME
              value: nfs.io/local
            - name: NFS_SERVER
              value: {{ .NFSServerIp}}
            - name: NFS_PATH
              value: {{ .NFSServerPath}}
      volumes:
        - name: nfs-client-root
          nfs:
            server: {{ .NFSServerIp}}
            path: {{ .NFSServerPath}}

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: nfs-client-provisioner
  namespace: kube-system
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: nfs-client-provisioner-runner
rules:
  - apiGroups: [""]
    resources: ["persistentvolumes"]
    verbs: ["get", "list", "watch", "create", "delete"]
  - apiGroups: [""]
    resources: ["persistentvolumeclaims"]
    verbs: ["get", "list", "watch", "update"]
  - apiGroups: ["storage.k8s.io"]
    resources: ["storageclasses"]
    verbs: ["get", "list", "watch"]
  - apiGroups: [""]
    resources: ["events"]
    verbs: ["list", "watch", "create", "update", "patch"]
  - apiGroups: [""]
    resources: ["endpoints"]
    verbs: ["create", "delete", "get", "list", "watch", "patch", "update"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: run-nfs-client-provisioner
subjects:
  - kind: ServiceAccount
    name: nfs-client-provisioner
    namespace: kube-system
roleRef:
  kind: ClusterRole
  name: nfs-client-provisioner-runner
  apiGroup: rbac.authorization.k8s.io

---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: local-nfs-storage
provisioner: nfs.io/local

`

type ClusterStorage struct {
	StoragePluginType string
}

type StoragePluginCeph struct {
	//rdb
	RbdStorageClass string
	RbdAdminId      string
	RbdAdminSecret  string
	RbdPool         string
	RbdUserId       string
	RbdUserSecret   string
	RbdFsType       string
	RbdImageFormat  int
}

type StoragePluginLVM struct {
	//LVM
	LocalVolumeEnabled        bool
	LocalVolumeIsDefaultClass bool
	LocalVolumeStorageClass   string
}

type StoragePluginNFS struct {
	NFSServerIp   string `json:"nfs_server"`
	NFSServerPath string `json:"nfs_path"`
}

func (nfs *StoragePluginNFS) ToYaml() string {
	return utils.Render(NFSManifests, nfs)
}

func (nfs *StoragePluginNFS) GetAppName() string {
	return "nfs"
}
